package com.mybatis.boost.domain.page;

import com.mybatis.boost.domain.sort.Order;

import javax.annotation.Nonnull;

/**
 * @author jearton
 * @since 2017/2/15
 */
public class PageRequest extends AbstractPageRequest {

    public PageRequest(int page) {
        super(page, PageConstants.DEFAULT_PAGE_SIZE);
    }

    public PageRequest(int page, int size) {
        super(page, size);
    }

    /**
     * @see PageBuilder
     */
    PageRequest(int page, int size, int defaultPageSize, int maxPageSize, boolean pageNumberOneIndexed,
                boolean fixEdge, Order... orders) {
        super(page, size, defaultPageSize, maxPageSize, pageNumberOneIndexed, fixEdge, orders);
    }

    PageRequest queryCount(boolean queryCount) {
        super.setQueryCount(queryCount);
        return this;
    }

    @Nonnull
    @Override
    public Pageable jumpTo(int page) {
        return PageBuilder.page(page)
                .size(getPageSize())
                .defaultPageSize(getDefaultPageSize())
                .maxPageSize(getMaxPageSize())
                .pageNumberOneIndexed(isPageNumberOneIndexed())
                .fixEdge(isFixEdge())
                .queryCount(isQueryCount())
                .sort(getSort())
                .build();
    }
}
